/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.sensor.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * @author I. de Vries
 */
@Entity
@Table(name = "GEOSENSORDATAFILE")
public class GeoSensorDataFileBO implements Serializable, DataFileBO//extends DataFileBO {
{
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="GEOSENSORDATAFILE_ID")
    private long dataFileId;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "sensorMetadataId")
    private SensorMetadataBO sensorMetadata;

    @Column(name="FILENAME")
    private String fileName;

    @Column(name="MD5_CHEKSUM")
    private String checksum;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="FILE_CREATED")
    private Date fileCreated;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="FILE_READ")
    private Date fileRead;

    @OneToMany(mappedBy="geoDataSensorFile", fetch=FetchType.EAGER)
    private Set<GeoSensorDataBO> geoSensorData = new HashSet<GeoSensorDataBO>();

    /**
     * For JPA use only.
     */
    @Deprecated
    protected GeoSensorDataFileBO() {
    }

    public GeoSensorDataFileBO(String fileName, String checksum, Date fileCreated, Date fileRead, SensorMetadataBO sensorMetadata) {
        this.fileName = fileName;
        this.checksum = checksum;
        this.fileCreated = fileCreated;
        this.fileRead = fileRead;
        this.sensorMetadata = sensorMetadata;
    }

//    public GeoSensorDataFileBO(String fileName, String checksum, Date fileCreated, Date fileRead) {
//        this.fileName = fileName;
//        this.checksum = checksum;
//        this.fileCreated = fileCreated;
//        this.fileRead = fileRead;
//    }

    public Date getFileRead() {
        return fileRead;
    }

    public void setFileRead(Date fileRead) {
        this.fileRead = fileRead;
    }


    public String getChecksum() {
        return checksum;
    }

    public void setChecksum(String checksum) {
        this.checksum = checksum;
    }

    public Date getFileCreated() {
        return fileCreated;
    }

    public void setFileCreated(Date fileCreated) {
        this.fileCreated = fileCreated;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public long getGeoSensorDataFileId() {
        return dataFileId;
    }

    public SensorMetadataBO getSensorMetadata() {
        return sensorMetadata;
    }

    public void setSensorMetadata(SensorMetadataBO sensorMetadata) {
        this.sensorMetadata = sensorMetadata;
    }

    /**
     * Constructor for creating a GeoSensorDataBO
     */
    public void addGeoSensorData(GeoSensorDataBO geoSensorDataBO) {
        geoSensorData.add(geoSensorDataBO);
    }

    public Set<GeoSensorDataBO> getGeoSensorData() {
        return geoSensorData;
    }


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GeoSensorDataFileBO other = (GeoSensorDataFileBO) obj;
        if ((this.fileName == null) ? (other.fileName != null) : !this.fileName.equals(other.fileName)) {
            return false;
        }
        if ((this.checksum == null) ? (other.checksum != null) : !this.checksum.equals(other.checksum)) {
            return false;
        }
        if (this.fileCreated != other.fileCreated && (this.fileCreated == null || !this.fileCreated.equals(other.fileCreated))) {
            return false;
        }
        if (this.fileRead != other.fileRead && (this.fileRead == null || !this.fileRead.equals(other.fileRead))) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + (this.fileName != null ? this.fileName.hashCode() : 0);
        hash = 29 * hash + (this.checksum != null ? this.checksum.hashCode() : 0);
        hash = 29 * hash + (this.fileCreated != null ? this.fileCreated.hashCode() : 0);
        hash = 29 * hash + (this.fileRead != null ? this.fileRead.hashCode() : 0);
        return hash;
    }

}